﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Sispe.Entities;
using Sispe.BussinesLogic;
using Microsoft.Practices.Unity;

namespace Sispe.UI
{
    public partial class frmExperienciaPostulante : Form
    {
        [Dependency]
        public IExperienciaPostulanteBL experienciaPostBL { get; set; }

        public frmExperienciaPostulante()
        {
            InitializeComponent();
            this.BuildUp();
        }

        public POSTULANTE CurrentPostulante { get; set; }

        public void condicionPostulante()
        {
            eXPERIENCIA_POSTULANTEBindingSource.DataSource = (from c in experienciaPostBL.GetAllFromExperienciaPostulante()
                                                  where c.IdPostulante.Equals(CurrentPostulante.IdPostulante)
                                                  select c).ToList();

            nombreCompletoLabel1.Text = CurrentPostulante.PERSONA.NombreCompleto;
        }

        public void cargaData()
        {
            eXPERIENCIA_POSTULANTEBindingSource.DataSource = (from c in experienciaPostBL.GetAllFromExperienciaPostulante()
                                                  where c.IdPostulante.Equals(CurrentPostulante.IdPostulante)
                                                  select c).ToList();
        }

        private void btnNuevo_Click(object sender, EventArgs e)
        {
            var CurrentExperienciaPostulante = eXPERIENCIA_POSTULANTEBindingSource.Current as EXPERIENCIA_POSTULANTE;
            var nomPostulante = nombreCompletoLabel1.Text;

            frmMttoExperienciaPostulante frm = new frmMttoExperienciaPostulante();
            frm.CurrPostulante = CurrentPostulante;
            frm.NuevaExperiencia(nomPostulante);
            frm.ShowDialog();
            cargaData();
        }

        private void btnEditar_Click(object sender, EventArgs e)
        {
            var experiencias = eXPERIENCIA_POSTULANTEBindingSource.Current as EXPERIENCIA_POSTULANTE;

            if (experiencias != null)
            {
                var nomPostulante = nombreCompletoLabel1.Text;
                frmMttoExperienciaPostulante frm = new frmMttoExperienciaPostulante();
                frm.CurrExperiencia  = experiencias;
                frm.EditarExperiencia(nomPostulante);
                frm.ShowDialog();
                cargaData();
            }
            else
            {
                MessageBox.Show("Debe seleccionar una Experiencia.", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
    }
}
